package com.tensai.study.java.newconcept.typereactiveprogram.reactor.mono;

import org.junit.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

/**
 * @author Tensai
 */
public class ContextTest {

	@Test
	public void contextSimple1() {
		String key = "message";
		Mono<String> r = Mono.just("Hello")
				.flatMap(s ->
						Mono.deferContextual(ctx ->
								Mono.just(s + " " + ctx.get(key))
						)
				)
				.contextWrite(ctx -> ctx.put(key, "World"));

		StepVerifier.create(r).expectNext("Hello World").verifyComplete();
	}

}
